using UnityEngine;
using System.Collections;

public class EnemySpawn : MonoBehaviour {
    // Enemy prefab
    public GameObject enemyPrefab;
    
    // Last time an enemy was spawned
    private float lastSpawnTime = -1.0f;
    // Shoot cooldown
    public float spawnRepeatTime = 5.0f;

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update ()
    {
        // maybe limit number of enemies
        if (Time.time > lastSpawnTime + spawnRepeatTime)
        {
            Spawn();
            lastSpawnTime = Time.time;
        }   
    }
    
    void Spawn()
    {
        Vector3 forward = transform.TransformDirection(Vector3.forward).normalized;
        
        GameObject spawn = Instantiate(enemyPrefab, this.transform.position + forward * 1 + new Vector3(0f,1.5f,0f), new Quaternion(1,0,0,1)) as GameObject;
        
        spawn.transform.parent = this.transform;
    }
}